
import { useAuthStore } from '@/store'
import { Modal } from 'ant-design-vue';

let isConfirming = false
export function resolveResError(code, message) {
  switch (code) {
    case 401:
      if (isConfirming) return
      isConfirming = true
      Modal.confirm({
        title: () => '提示',
        content: () => '登录已过期，是否重新登录',
        onOk() {
          console.log('OK');
          useAuthStore().logout()
          window.$message?.success('已退出登录')
          isConfirming = false
        },
        onCancel() {
          console.log('Cancel');
          isConfirming = false
        },
        class: 'test',
      });
      return false
    case 11007:
    case 11008:
      if (isConfirming) return
      isConfirming = true
      $dialog.confirm({
        title: '提示',
        type: 'info',
        content: `${message}，是否重新登录？`,
        confirm() {
          useAuthStore().logout()
          window.$message?.success('已退出登录')
          isConfirming = false
        },
        cancel() {
          isConfirming = false
        },
      })
      return false
    case 403:
      message = '请求被拒绝'
      break
    case 404:
      message = '请求资源或接口不存在'
      break
    default:
      message = message ?? `【${code}】: 未知异常!`
      break
  }
  return message
}
